import api from '../../api';
import _ from 'lodash';

export default {
  namespace: 'bpmnM',
  state: {},
  effects: {
    *getRoleList({ payload, callback }, { call, put, select }) {
      const res = yield call(api.getRoleList, payload);
      if (res && res.success) {
        const data = [];
        res.data.map((item) => {
          data.push({
            value: item.id,
            title: item.roleName,
          });
        });
        callback(data);
      }
    },
    // 岗位列表数据
    *getStationList({ payload, callback }, { call, put }) {
      const res = yield call(api.stationManage.Search, payload);
      if (res && res.success) {
        callback(
          res.data.map((item) => {
            return { value: item.id, title: item.postName };
          }),
        );
      } else {
        message.error(`岗位列表查询失败，失败原因：${res?.message}`);
        console.error(`岗位列表查询失败，失败原因：${res?.message}`, '接口名称：condition 接口：portfolio-server/station/condition');
      }
    },
    *getUserList({ payload, callback }, { call, put, select }) {
      const res = yield call(api.getUserList, payload);
      if (res && res.success) {
        const data = [];
        res.data.map((item) => {
          data.push({
            value: item.userId,
            title: item.name,
          });
        });
        callback(data);
      }
    },
    //获取某公式对应的描述
    *getBpmnRemarkInfo({ payload, callback }, { call, put, select }) {
      console.log(payload);
      const res = yield call(api.getBpmnRemarkInfo, payload);
      if (res && res.code == 0) {
        callback(res.data ? res.data.description : '');
      } else {
        callback('fail');
      }
    },
    //保存某公式对应的描述
    *saveBpmnRemarkInfo({ payload, callback }, { call, put, select }) {
      const res = yield call(api.saveBpmnRemarkInfo, payload);
      if (res && res.code == 0) {
        callback('success');
      } else {
        callback();
      }
    },
  },

  reducers: {
    setState(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
